<html>
<div id="myheader">
<?php
session_start();
$user_id = $_SESSION['user_id'];
$user_name = $_SESSION['user_name'];
?>
</div>

<title>OSPMS</title>
<head>
<link rel="stylesheet" href="style/ospms.css" type="text/css">
  <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
<style type="text/css" media="all">

#listDiv{width:600px;overflow:auto;}
#updateDiv{width:300px; vertical-align:top;}
#middleDiv{ height:500px; width:2px; background:darkgray;}
</style>
</head>
<?php
include "include/dbConfig.php";

session_start();

try {
    $conn = new PDO("mysql:host=$dbservername;dbname=$dbname", $dbusername, $dbpassword);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

	$query = "SELECT project_id, project_name,project_description FROM user_projects where user_id = ". $user_id;
    $stmt = $conn->prepare($query);
    $stmt->execute();
    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
$array_project = $stmt->fetchAll();

    $dsn = null;

} // try
catch(PDOException $e)
{
    echo "Error: " . $e->getMessage();
} // try - catch

$conn = null;
?> 


<form method="get" action="AddProject.php">   <!-- default: get; all post most be specified -->
<div id="subMain">

<table><tr>
<td valign="top">
<div id="listDiv">
<?php

$num=0;
echo "<table border='1'cellpadding='5' cellspacing='5' class='DataTable'>";
echo "<tr><th>Project Name</th><th>Project Description</th><th>Edit</th></tr>";
foreach($array_project as $key => $oneProject)
{
	$num++;
	if($num%2==1)
		echo "<tr class='tableData'>";
	else 
		echo "<tr class='tableData2'>";
	echo "<td>". $oneProject['project_name']."</td>";
	echo "<td>". $oneProject['project_description']."</td>";
	echo "<td><a href='javascript:void()' onclick=\"clickUpdate('".$oneProject['project_id']."','".$oneProject['project_name']."','".$oneProject['project_description']."')\">Edit</a>
	/<a  href='javascript:void()' onclick=\"clickDelete('".$oneProject['project_id']."','".$oneProject['project_name']."','".$oneProject['project_description']."')\">Del</a>
	</td>";
	echo "</tr>";
	
}
echo "</table>"

?>
</div>
</td>
<td valign="middle">
<div id="middleDiv"></div>
</td>
<td valign="top">
<div id="updateDiv">
<table class="editTable" >
	<tr>
      <td class="lefttd">Name:</td>
      <td class="righttd"><input type="text" name="projectName" value=""  class="text"/></td>
    </tr>
    <tr>
      <td class="lefttd">Description:</td>
      <td class="righttd"><input type="text" name="projectDescription" class="text"/></td>
    </tr>
    <tr>
      <td class="righttd" colspan="2" style="" >
	<input type="hidden" name="projectID" value="">
        <input type="submit" value="Update/Add Project" class="ActionButton" name="cmdLogin" id="cmdLogin"/>
      </td>
    </tr>
</table>
</div>
</td>
</tr></table>
</div>
</form>

<script>
function clickUpdate(id,projectName,projectDescription)
	{
		$("[name='projectName']").val(projectName);
		$("[name='projectDescription']").val(projectDescription);
		$("[name='projectID']").val(id);

	}
	function clickDelete(id,projectName,projectDescription)
	{
		window.location.href="AddProject.php?actionType=Del&projectID="+id;
	}
	
	$("#listDiv").css("height",$(document.body).height()-10);
</script>
